package subumbo.demo.view.firework {
	import flash.display.BitmapData;
	import flash.geom.Point;
	import flash.text.TextField;
	import flash.text.TextFieldAutoSize;
	import flash.text.TextFormat;
	
	import org.flintparticles.common.actions.Age;
	import org.flintparticles.common.actions.Fade;
	import org.flintparticles.common.counters.Blast;
	import org.flintparticles.common.energyEasing.Quadratic;
	import org.flintparticles.common.initializers.ColorInit;
	import org.flintparticles.common.initializers.Lifetime;
	import org.flintparticles.twoD.actions.Accelerate;
	import org.flintparticles.twoD.actions.LinearDrag;
	import org.flintparticles.twoD.actions.Move;
	import org.flintparticles.twoD.emitters.Emitter2D;
	import org.flintparticles.twoD.initializers.Position;
	import org.flintparticles.twoD.initializers.Velocity;
	import org.flintparticles.twoD.zones.BitmapDataZone;
	import org.flintparticles.twoD.zones.DiscZone;

	public class TextEmitter extends Emitter2D {
		
		private var _txt:TextField;
		private var _bmd:BitmapData;
		
		public function TextEmitter(val:String) {
			
			_txt = new TextField();
      		_txt.multiline = false;
      		_txt.height = 100;
      		_txt.autoSize = TextFieldAutoSize.LEFT;
      		var format:TextFormat = _txt.defaultTextFormat;
      		format.size = 100;
      		format.font = "Arial"
      		format.kerning = 10;
      		_txt.defaultTextFormat = format;
			_txt.text = val;
			
			_bmd = new BitmapData(_txt.width,200, true,0x00000000);
			_bmd.draw(_txt );
			
			
			counter = new Blast(4000);	
			addInitializer( new ColorInit( Math.random()  *  0xFFFFFF00, Math.random()  *  0xFFFFFF00 ) );
      		addInitializer( new Lifetime( 6 ) );
      		addInitializer( new Position( new DiscZone( new Point( 0, 0 ), 10 ) ) );
      		addInitializer( new Velocity( new BitmapDataZone( _bmd, -132, -300 ) ) );
      
      		addAction( new Age( Quadratic.easeIn ) );
      		addAction( new Fade( 1.0, 0 ) );
      		addAction( new Move() );
      		addAction( new LinearDrag( 0.5 ) );
      		addAction( new Accelerate( 0, 70 ) );

      
      		
		}
		
		public function set text(val:String):void {
			_txt.text = val;
			_bmd.draw(_txt);
		}
	    
	    
	    
	    public function get textField():TextField {
	    	return _txt;
	    }

	}
}